CC= $(CROSS_COMPILE)g++
CXXFLAGS= -fPIC -Wall -ggdb3 -D__STDC_CONSTANT_MACROS
#CFLAGS= -fPIC -Wall -ggdb3 -D__STDC_CONSTANT_MACROS
LDFLAGS= -shared -pthread
FFMPEG_LIBS=libavfilter
SRC=overlay.cpp osdependent_func.cpp

#default library name
LIB=libOverlay.so
SYS := $(shell gcc -dumpmachine)
ifneq (, $(findstring linux, $(SYS)))
FFMPEG_LIBS= libavdevice libavformat libavfilter libavcodec libswresample libswscale libavutil
LIBS := $(shell pkg-config --libs $(FFMPEG_LIBS)) $(LIBS)
LIB=libOverlay.so
endif

ifneq (, $(findstring mingw, $(SYS)))
LIB=libOverlay.dll
endif

ifneq (, $(findstring cygwin, $(SYS)))
LIB=libOverlay.dll
#LIBS= -L/usr/lib -L/usr/local/lib /usr/local/lib/libx264.a -lavfilter -lswresample -lswscale -lavformat -lavcodec -lbz2 -lz -lavutil -lm -lfreetype -lpostproc -lfaac
CXXFLAGS += -DWINDOWS -static-libgcc -static-libstdc++ -I/usr/local/include/
CXX=x86_64-w64-mingw32-g++
LIBS= -L/usr/lib -L./lib -lavfilter ./lib/swresample-0.dll -lswscale -lavformat -lavcodec -lavutil -lpostproc -lws2_32 

endif

OBJ=$(SRC:.cpp=.o)

all: $(LIB)

$(LIB): $(OBJ)
	$(CXX) -o $@ $(CXXFLAGS) $(OBJ) -Wl,--whole-archive $(LDFLAGS) $(LIBS) -Wl,--no-whole-archive 
clean:
	rm -rf $(OBJ) libOverlay.dll libOverlay.so


